const runtimeGenerator = require('svg-sprite-loader/lib/runtime-generator.js');
const BrowserSpriteSymbol = require('svg-baker-runtime/browser-symbol.js');

let count = 0;

const originGenerator = runtimeGenerator.runtimeGenerator;
/**
 * @param {Object} params
 * @param {SpriteSymbol} params.symbol - Sprite symbol instance {@see https://git.io/v9k8g}
 * @param {SVGSpriteLoaderConfig} params.config - Parsed loader config
 * @param {string} params.context - Context folder of current processing module
 * @param {Object} params.loaderContext {@see https://webpack.js.org/api/loaders/#the-loader-context}
 * @return {string}
 */
runtimeGenerator.runtimeGenerator = function (params) {
	const symbolGlobalVarName = '__SVG_SYMBOL__';
	if (!window[symbolGlobalVarName]) {
		window[symbolGlobalVarName] = BrowserSpriteSymbol;
	}

	window.RRR = ++count;

	return originGenerator(params);
};

module.exports = runtimeGenerator;
